#ifndef REDIS_H
#define REDIS_H

#include <hiredis/hiredis.h>
#include <functional>
#include <string>

using namespace std;

class Redis {
public:
    Redis();
    ~Redis();

    //连接redis服务器
    bool connect();
    //发布消息
    bool publish(int channel, string messgae);
    //订阅频道
    bool subscribe(int channel);
    //取消订阅频道
    bool unsubscribe(int channel);
    //接收频道消息
    void observer_channel_message();
    //设置回调
    void init_notify_handler(function<void(int, string)> fn);

private:
    function<void(int, string)> notify_message_handler;
    //用于发布消息
    redisContext* publish_context;
    //用于订阅频道
    redisContext* subscribe_context;    
};

#endif